﻿// 1.1.7.09. Write a program, which finds a subsequence of numbers with maximal sum.
// E.g.: {2, 3, -6, -1, 2, -1, 6, 4, -8, 8} -> 11
// Can you do it with only one loop (with single scan through the elements of the array)?

using System;

class SubsequenceWithMaximalSum
{
    static void Main()
    {
        int[] arr = new int[] { 2, 3, -6, -1, 2, -1, 6, 4, -8, 8 };
        int maxSum = int.MinValue;
        for (int i = 0; i < arr.GetLength(0) - 1; i++)
        {
            int currentSum = 0;
            for (int j = i; j < arr.GetLength(0); j++)
            {
                currentSum += arr[j];
                if (currentSum > maxSum)
                {
                    maxSum = currentSum;
                }
            }
        }
        Console.WriteLine(maxSum);
    }
}